<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="years" label="年份">
          <!-- <a-input placeholder="请输入years" v-model="model.years" /> -->
          <a-date-picker
            placeholder="请选择年份"
            mode="year"
            :open="dataopen"
            format="YYYY"
            valueFormat="YYYY"
            :allowClear="false"
            @openChange="openChangeYear"
            @panelChange="panelChangeYear"
            v-model="model.years"
            style="width:100%"
          />
        </a-form-model-item>
        
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cid" label="所属产业">
          <j-search-select-tag placeholder="请选择产业集群" v-model="model.cid" dict="ind_cluster,name,id" :pageSize="10" :async="true" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ys" label="营收（万元）">
          <a-input-number placeholder="请输入" v-model="model.ys" style="width:100%"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sj" label="税金（万元）">
          <a-input-number placeholder="请输入" v-model="model.sj" style="width:100%"/>
        </a-form-model-item>
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "IndJqsjModal",
    data () {
      return {
        title:"操作",
        visible: false,
        dataopen:false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
          years:{
            rules: [{
              required: true, message: '请选择年份！',
            }],
          },
        },
        url: {
          add: "/indust/indJqsj/add",
          edit: "/indust/indJqsj/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },
      openChangeYear(status) {
        if (status) {
          this.dataopen = true;
        } else {
          this.dataopen = false;
        }
      },
      // 选择年之后 关闭弹框
      panelChangeYear(value){
        this.model.years = moment(value).format('YYYY')
        this.dataopen = false;
      },

    }
  }
</script>

<style lang="less" scoped>

</style>